package com.bee.plus.user.controller;

import cn.hutool.json.JSONObject;
import com.bee.plus.common.R;
import com.bee.plus.user.dto.LoginReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/api/user")
@Api(description = "管理后台api",tags="管理后台——登录")
public class UserController {

    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/login")
    @ApiOperation(value = "登录", notes = "传入意向客户参数")
    public R save(@RequestBody LoginReq dto) {
        if(!dto.getUsername().equals("admin")){
            return R.data(-1,-1,"");
        }
        if(!dto.getPassword().equals("123qweasd")){
            return R.data(-1,-1,"");
        }
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("token","admin-token");
        return R.data(jsonObject);
    }

    @GetMapping("/info")
    @ApiOperation(value = "获取用户信息", notes = "传入意向客户参数")
    public R info(@RequestParam("token") String  token) {
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("introduction","I am a super administrator");
        jsonObject.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        jsonObject.put("name","Super Admin");
        List<String> list=new ArrayList();
        list.add("admin");
        jsonObject.put("roles", list);
        return R.data(jsonObject);
    }

    @PostMapping("/logout")
    @ApiOperation(value = "获取用户信息", notes = "传入意向客户参数")
    public R logout() {
        JSONObject jsonObject=new JSONObject();
        return R.data(jsonObject);
    }
}
